#include "FmodSound.h"


FmodSound::FmodSound(GSoundType _type,char *_soundPath)
{
	type=_type;
	soundPath=_soundPath;
	
	FMOD_RESULT result = FMOD::System_Create(&soundSystem);
	FMOD_RESULT fm_res = soundSystem->init(100,FMOD_INIT_NORMAL,0);

	switch(type)
	{
	case GSoundType::BACKGROUND_SOUND:
		soundSystem->createStream(soundPath,FMOD_SOFTWARE | FMOD_LOOP_NORMAL,0,&sound);
		break;
	case GSoundType::EFFECT_SOUND:
		soundSystem->createSound(soundPath, FMOD_SOFTWARE,0,&sound);
		break;
	}
}


FmodSound::~FmodSound(void)
{
	sound->release();
}

void FmodSound::GUpdateSoundSystem()
{
	soundSystem->update();
}

void FmodSound::GCreateSound()
{
	switch(type)
	{
	case GSoundType::BACKGROUND_SOUND:
		soundSystem->createStream(soundPath,FMOD_SOFTWARE | FMOD_LOOP_NORMAL,0,&sound);
		break;
	case GSoundType::EFFECT_SOUND:
		soundSystem->createSound(soundPath, FMOD_DEFAULT,0,&sound);
		break;
	}
}

void FmodSound::GPlaySound()
{
	
	soundSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
	switch(type)
	{
	case GSoundType::BACKGROUND_SOUND:
		soundSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
		break;
	case GSoundType::EFFECT_SOUND:
		soundSystem->playSound(FMOD_CHANNEL_FREE, sound, false, 0);
		break;
	}

}

void FmodSound::GSetPaused(bool paused)
{
	soundChannel->setPaused(paused);
	//////////////////////////////////////////////////////////////////////////
	
}

bool FmodSound::GGetPaused()
{
	bool paused;
	soundChannel->getPaused(&paused);
	return paused;
}

void FmodSound::GSetVolume(float _volume)
{
	soundChannel->setMute(true);
}